package com.llyb.service.impl;

import com.llyb.entities.Order;
import com.llyb.entities.User;
import com.llyb.feign.UserFeignClient;
import com.llyb.mapper.OrderMapper;
import com.llyb.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper ;

    @Autowired
    private UserFeignClient userFeignClient;

    @Override
    public Order findOrderByOrderId(Long orderId) {

        Order order = orderMapper.findOrderByOrderId(orderId);

        /* 发起远程调用
        User user = restTemplate.getForObject("http://localhost:10100/api/user/findUserByUserId/" + order.getUserId(), User.class);
        order.setUser(user);*/

        /*// 服务提供方的服务ip地址和端口号可以使用服务提供方的服务名称进行替换
        User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/" + order.getUserId(), User.class);
        order.setUser(user);*/

        User user = userFeignClient.queryById(order.getUserId());
        order.setUser(user);

        return order;
    }
}


/*public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper ;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Order findOrderByOrderId(Long orderId) {

        Order order = orderMapper.findOrderByOrderId(orderId);

        /*//*/ 发起远程调用
        User user = restTemplate.getForObject("http://localhost:10100/api/user/findUserByUserId/" + order.getUserId(), User.class);
        order.setUser(user);*//*

        // 服务提供方的服务ip地址和端口号可以使用服务提供方的服务名称进行替换
        User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/" + order.getUserId(), User.class);
        order.setUser(user);

        return order;
    }
}*/
